
#ifndef NOSAL_EXEC_INTERNAL_FILESYSTEM_EXCEPTION_H_
#define NOSAL_EXEC_INTERNAL_FILESYSTEM_EXCEPTION_H_

#include "common/exception.h"

#include <string>
#include <errno.h>
#include <string.h>

namespace netaos {
namespace nosal {
namespace exec {
namespace internal {

/// @brief This exception signals that an error occurred while accessing the file system.
class FilesystemException : public Exception
{
    using Parent = Exception;

public:
    /// @brief Constructor.
    ///
    /// @param fileName the name of the file who's access triggered the error.
    /// @param errorNumber the errno set by the failed call to exec().
    FilesystemException(const std::string& fileName, std::int32_t const errorNumber) noexcept
        : Parent(GenerateMessage(fileName, errorNumber))
    { }

private:
    /// @brief Constructor.
    ///
    /// @param fileName the name of the file who's access triggered the error.
    /// @param errorNumber the errno set by the failed call to exec().
    static std::string GenerateMessage(const std::string& fileName, std::int32_t const errorNumber) noexcept
    {
        std::string message("Error ");
        message += std::to_string(errorNumber);
        message += " accessing file '";
        message += fileName;
        message += "' : ";
        message += ::strerror(errorNumber);
        return message;
    }
};

}  // namespace internal
}  // namespace exec
}  // namespace nosal
}  // namespace netaos

#endif  // NOSAL_EXEC_INTERNAL_FILESYSTEM_EXCEPTION_H_
